package com.example.demo.controller;

import com.aliyuncs.exceptions.ClientException;
import com.example.demo.service.SmsService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestParam;
import org.springframework.web.bind.annotation.RestController;

@RestController
@RequestMapping("/api/student")
public class SmsController {

    @Autowired
    private SmsService smsService;

    @GetMapping("/send-sms")
    public String sendSms(@RequestParam String phoneNumber, @RequestParam String code) throws ClientException {
        // 发送短信，code 是要发送的验证码或消息
        String templateParam = "{\"code\":\"" + code + "\"}";
        boolean isSent = smsService.sendSms(phoneNumber, templateParam);

        if (isSent) {
            return "短信发送成功";
        } else {
            return "短信发送失败";
        }
    }
}

